#pragma once

#include <Ogre.h>
#include <map>
#include <string>

using namespace Ogre;
using namespace std;

class FrameTiming 
{
public:
	FrameTiming();
	~FrameTiming();

	static FrameTiming* getSingleton();
	void doFrameTiming();
	float timeSinceLastFrame();
	void addTimer(string name, unsigned long period, void (*callback)(void*), void* data);
	void delTimer(string name);
	static void updateFramerateDisplay(void *data);
protected:
	static FrameTiming* singleton;

	class TimerInfo {
	public:
		TimerInfo(unsigned long period, void (*callback)(void*), void* data);
		TimerInfo(const TimerInfo &timerInfo);
		TimerInfo() {}
		
		void (*callback)(void*);
		unsigned long elapsed;
		unsigned long period;
		void* data;
	};
	map<string, TimerInfo> timers;
	
	Timer timer;
	unsigned long tprev; /// Guarda el momento en que se renderizo el frame anterior. En microsegundos
	unsigned long tcurrent; /// Guarda el momento en que se renderizo el frame actual. En microsegundos
};

